<?php

namespace app\admin\model;

use app\common\model\BaseModel;


class Subject extends BaseModel
{


    // 表名
    protected $name = 'subject';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;



    public function getList($where, $size = 12, $field = '*', $order = 'id desc')
    {
        $list = $this->where(function ($query) use ($where) {
            if (isset($where['keywords']) && $where['keywords']) {
                $query->where('name', "like", "%{$where['keywords']}%");
            }
            if (isset($where['category_id']) && $where['category_id']) {
                $query->where('category_id', $where['category_id']);
            }
            if (isset($where['subject_id']) && $where['subject_id']) {
                $query->where('id', 'in', $where['subject_id']);
            }
        })
            ->with([])
            ->field($field)
            ->order($order)
            ->paginate($size);
        //$list->each(function ($item) {
        //});
        return $list->toArray();

    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getStatusList()
    {
        return [ '1' => __('Status 1'),'0' => __('Status 0')];
    }



}
